Skip to content

Conversation

TabLand
Copy link

@TabLand TabLand commented Jul 3, 2025

@TabLand TabLand force-pushed the correct-multi-index-rename-checks branch from d700c92 to 6b7cba3 Compare July 3, 2025 19:53
@TabLand TabLand marked this pull request as ready for review July 5, 2025 10:56
Comment on lines 1054 to 1058
indexers = [
ax.get_level_values(i).get_indexer_for([replacement])
for i in range(ax.nlevels)
if i == level or level is None
]
Copy link
Member

@mroeschke mroeschke Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think MultiIndex.get_indexer_for should work with for an iterable of tuples, so I would look into why that isn't working as opposed to working around it here

@TabLand TabLand marked this pull request as draft July 8, 2025 21:54
@TabLand TabLand force-pushed the correct-multi-index-rename-checks branch from 6b7cba3 to 0fd6ca7 Compare July 8, 2025 21:54
@@ -6429,12 +6429,15 @@ def _transform_index(self, func, *, level=None) -> Index:
Only apply function to one level of the MultiIndex if level is specified.
"""
if isinstance(self, ABCMultiIndex):
values = [
self.get_level_values(i).map(func)
if i == level or level is None
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mroeschke - I've managed to trace this issue to this line here. The Index._transform_index function is only used in one other place: merge.py>_items_overlap_with_suffix

Checking if this has had an adverse impact on other tests...

Copy link
Author

@TabLand TabLand Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like certain existing transformations have to be applied to each individual level component of a MultiIndex, whereas others make more sense to apply to the entire thing.

I'm guessing a new parameter to DataFrame.rename() is needed which could then be cascaded down to Index._transform_index()? Something like scope: {"full", "partial"}?

Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Pandas column rename function now working for multilevel columns
3 participants